<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>login</title>
    <link href="../static/css/login.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<div class="content">
    <div class="middle_column">
        <div class="zh_title">学生选课管理系统</div>
        <div class="en_title">Student Selection Management System</div>
        <div class="layui-form-item">
            <label class="layui-form-label">账号:</label>
            <div class="layui-input-block">
                <input type="text" name="username" id="username" lay-verify="required"  placeholder="学生请填写学号/老师填账号" autocomplete="off" class="layui-input account_input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码:</label>
            <div class="layui-input-block">
                <input type="password" name="password" id="password" lay-verify="required"  placeholder="请输入账号密码" autocomplete="off" class="layui-input account_input">
            </div>
        </div>
        <div class="layui-form-item" pane="">
            <label class="layui-form-label role_title">账号权限:</label>
            <div class="layui-input-block" id="check_type">
                <input type="radio" id="role1" class="role_input  left_input" name="type" value="1" title="学生" checked=""><span class="label">学生</span>
                <input type="radio" id="role2" class="role_input " name="type" value="2" title="教师"><span class="label">教师</span>
                <input type="radio" id="role3" class="role_input " name="type" value="3" title="管理员"><span class="label">管理员</span>
            </div>
        </div>
        <div class="sub_column">
            <button type="button" class="layui-btn layui-btn-lg" id="login_btn">登录</button>
        </div>
        <div class="go_register">
            没有账号,快来注册吧> <a href="register?type=1">学生注册</a> <a href="register?type=2">教师注册</a>
        </div>
    </div>
</div>

</body>
<link rel="stylesheet" href="../static/layui/css/layui.css">
<script src="../static/layui/layui.js"></script>
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form ,
            layer = layui.layer ;
        layui.$('#login_btn').on('click', function(){
            var username = document.getElementById("username").value;
            var password = document.getElementById("password").value;
            var check_type = layui.$('#check_type input[name="type"]:checked ').val();
            var data = {
                'password': password
            };
            if('1' == check_type){
                data.studentNumber = username;
            }else{
                data.loginName = username;
            }
            data = JSON.stringify(data);
            layui.jquery.ajax({
                url: '1' == check_type ? '/student/login' : ('2' == check_type?'/teacher/login':'/manage/login'),
                method: 'post',
                data: data,
                contentType: "application/json;charset=utf-8",
                traditional: true,
                dataType: 'html',
                success: function (res) {
                    document.write(res);
                }
            });
        });
    })
</script>
</html>